package com.example.android_20190604_01;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.ButterKnife;
import android.view.View.OnClickListener;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    public TextView textView;

//--------------------Butterknife----------------------
    @butterknife.OnClick(R.id.BT06)
    public void show() {
        textView.setText("点击了ButterKnife绑定的监听器");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView=findViewById(R.id.txt);

// ----------------------Activity---------------------------------------
        Button BT1;
        BT1 = findViewById(R.id.BT01);
        BT1.setOnClickListener(MainActivity.this);

// -----------------------匿名内部类-----------------------------------
// 适用于对监听器进行一次性使用的情况，在该代码块运行完毕之后，该监听器也就不复存在了。
        Button BT2;
        BT2 =(Button)findViewById(R.id.BT02);
        BT2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view)
            {
                Toast.makeText(MainActivity.this,"匿名内部类",Toast.LENGTH_SHORT);
                textView.setText("点击了采用匿名内部类绑定的监听器");
            }
        });

//----------------------内部类-----------------------------------------------
        Button BT4;
        BT4 = findViewById(R.id.BT04);
        BT4.setOnClickListener(new InnerClick());

//-----------------------外部类-------------------------------------------
        Button BT5;
        BT5 = findViewById(R.id.BT05);
        BT5.setOnClickListener(new clicklistener(MainActivity.this, textView));

// -------------------ButterKnife--------------------------------------
        ButterKnife.bind(this);

//-------------------configuration 系统信息--------------------------------------------
        Button BT7;
        BT7=findViewById(R.id.BT07);
        BT7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this, configuration.class);
                startActivity(intent);
            }
        });

//------------------------进度条-------------------------------------
        Button BT8;
        BT8=findViewById(R.id.BT08);
        BT8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this, progressdialog.class);
                startActivity(intent);
            }
        });
    }
//--------------Activity_onClick----------------------
    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.BT01)
        {
            textView.setText("点击了采用Activity绑定的监听器");
        }
    }
//-----------绑定到标签------------------------------------------------
    public void tag(View v) {
        if(v.getId()==R.id.BT03)
        {
            textView.setText("点击了采用绑定到标签的监听器");
        }
    }
//--------------内部类----------------------------------------------
    class InnerClick implements View.OnClickListener
    {
        @Override
        public void onClick(View v)
        {
            textView.setText("点击了采用内部类绑定的监听器");
        }
    }

}
